/**
 * 打印链表的输出
 */

public class Print {
    public static void print(ListNode head,int n) {
        // 遍历输出环链表
        ListNode curr = head;
        int count = 0;
        System.out.println("经过环循环得到的链表为（2倍长度）：");
        while (count < n*2 && curr.next != null) {  // 控制输出次数，避免死循环
            System.out.print(curr.val+"->");
            curr = curr.next;
            count++;
        }
        System.out.print(curr.val);
    }

    public static void print1(ListNode head){
        ListNode curr=head;
        while(curr!=null){
            System.out.println(curr.val+" ");
            curr=curr.next;
        }
    }
}